﻿<#--
定义用于生成实体的macro和function
-->
<@pp.dropOutputFile />
<#function v str>
	<#if str?trim != "">
		<#return true>
	<#else>
		<#return false>
	</#if>
</#function>

<#function vSeq seq>
	<#if (seq?size > 0)>
		<#return true>
	<#else>
		<#return false>
	</#if>
</#function>

<#function vHash hash>
	<#if (hash?keys?size > 0)>
		<#list hash?keys as key>
			<#if hash[key]?is_string>
				<#if hash[key]?trim != "">
					<#return true>
				</#if>		
			<#elseif hash[key]?is_sequence>
				<#if (hash[key]?size > 0)>
					<#return true>
				</#if>
			<#else>
				<#return true>			
			</#if>
		</#list>
		<#return false>			
	</#if>
		<#return false>		
</#function>

					  
<#--用于把str1,str2转变为"str1", "str2"-->
<#function addQuote srcString>
	<#assign outString = srcString?split(",")>
	<#assign retValue = "">
		<#list outString as o>
			<#assign retValue = retValue + "\"" + o?trim + "\", ">
		</#list>
		<#return retValue?substring(0, retValue?length - 2)>
</#function>

<#function p var, label="name", flag = true>
	<#if var=="">
		<#return "">
	<#else>
		<#if flag>
			<#return ", " + label + " = \"" + var?trim + "\"">
		<#else>
			<#return label + " = \"" + var?trim + "\"">
		</#if>
	</#if>
</#function>			

<#function pb var, label="name", flag = true>
	<#if var=="">
		<#return "">
	<#else>
		<#if flag>
			<#return ", " + label + " = " + var?trim >
		<#else>
			<#return label + " = " + var?trim >
		</#if>
	</#if>
</#function>		

<#function pn var, label="name", flag = true>
	<#if var=="">
		<#return "">
	<#else>
		<#if flag>
			<#return ", " + label + " = " + var?trim >
		<#else>
			<#return label + " = " + var?trim >
		</#if>
	</#if>
</#function>	

<#--
<#function pUniqueConstriants ucSeq, flag=true>
	<#if (ucSeq?size > 0) >
			<#if flag>
				<#local retValue = ", uniqueConstriants = {">
			<#else>
				<#local retValue = "uniqueConstriants = {">
			</#if>
		<#list ucSeq as l>
			<#local retValue = retValue + "@UniqueConstriant = (columnNames = {" + addQuote(l!) + "}), ">
		</#list>
				<#local retValue = retValue?substring(0, retValue?length - 2) + "}">
		<#return retValue>
	<#else>
		<#return "">
	</#if>
</#function>
-->		


<#macro Column column>
	<#if vHash(column)>
<@compress single_line=true>
		@Column(
		<#local f = false>
		<#if column.name??>
			${p(column.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if column.unique??>
			${pb(column.unique!, "unique", f)}
			<#local f = true>
		</#if>
		<#if column.nullable??>
			${pb(column.nullable!, "nullable", f)}
			<#local f = true>
		</#if>
		<#if column.insertable??>
			${pb(column.insertable!, "insertable", f)}
			<#local f = true>
		</#if>
		<#if column.updatable??>
			${pb(column.updatable!, "updatable", f)}
			<#local f = true>
		</#if>
		<#if column.columnDefinition??>
			${p(column.columnDefinition!, "columnDefinition", f)}
			<#local f = true>
		</#if>
		<#if column.table??>
			${p(column.table!, "table", f)}
			<#local f = true>
		</#if>
		<#if column.length??>
			${pn(column.length!, "length", f)}
			<#local f = true>
		</#if>
		<#if column.precision??>
			${pn(column.precision!, "precision", f)}
			<#local f = true>
		</#if>
		<#if column.scale??>
			${pn(column.scale!, "scale", f)}
			<#local f = true>
		</#if>
)</@compress>
	</#if>	
</#macro>	

	 
<#macro UniqueConstraint item>
	@UniqueConstraint(<#if item??>columnNames = {${addQuote(item!)}}</#if>)
</#macro>
						
<#macro UniqueConstraints ucSeq>
	<#if ucSeq??>
	<#if (ucSeq?size > 0)>
		<#if (ucSeq?size == 1)>
<@compress single_line=true>
uniqueConstraints = 
			<@UniqueConstraint ucSeq[0]! /></@compress>
		<#else>
uniqueConstraints = ({			
<#list ucSeq as item>
<@compress single_line=true>
			<@UniqueConstraint item! /><#if item_has_next>, </#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>	
		
<#macro Entity e>
	<#if e.embeddable!false >
@Embeddable
	<#elseif e.mappedSuperClass!false >
@MappedSuperClass
	<#else>
@Entity				
	</#if>	
</#macro>	
<#--
定义用于生成实体的macro和function

<#macro Table e>
	<#if e.table??>
@Table{
	<#local f=false>
	<#if e.table.name)>
		${p(e.table.name!, "name", f)}
		<#local f=true>
	</#if>
	<#if e.table.catalog)>
		${p(e.table.catalog!, "catalog", f)}
		<#local f=true>
	</#if>
	<#if e.table.schema)>
		${p(e.table.schema!, "schema", f)}
		<#local f=true>
	</#if>
	<#if e.table.uniqueConstraints??>
		${pUniqueConstriants(e.table.uniqueConstraints!, f)}
	</#if>
	}
	</#if>
</#macro>
-->
<#macro Inheritance inheritance>
	<#if inheritance??>
@Inheritance(${p(inheritance!, "strategy", false)}) 		
	</#if>
</#macro>			


<#macro PrimaryKeyJoinColumn item>
	<#if item??>
<@compress single_line=true>
	@PrimaryKeyJoinColumn(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if item.referencedColumnName??>
			${p(item.referencedColumnName!, "referencedColumnName", f)}
			<#local f = true>
		</#if>
		<#if item.columnDefinition??>
			${p(item.columnDefinition!, "columnDefinition", f)}
			<#local f = true>
		</#if>
		)</@compress>
	</#if>
</#macro>
						
<#macro PrimaryKeyJoinColumns primaryKeyJoinColumns>
	<#if primaryKeyJoinColumns??>
	<#if (primaryKeyJoinColumns?size > 0)>
		<#if (primaryKeyJoinColumns?size == 1)>
			<@PrimaryKeyJoinColumn primaryKeyJoinColumns[0]! />
		<#else>
@PrimaryKeyJoinColumns({			
<#list primaryKeyJoinColumns as pk>
<@compress single_line=true>
			<@PrimaryKeyJoinColumn pk! /><#if pk_has_next>, </#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>			
		
						
<#macro pkJoinColumns seq>
	<#if seq??>
	<#if (seq?size > 0)>
		<#if (seq?size == 1)>
<@compress single_line=true>
pkJoinColumns = 
			<@PrimaryKeyJoinColumn seq[0]! /></@compress>
		<#else>
pkJoinColumns = ({			
<#list seq as item>
<@compress single_line=true>
			<@PrimaryKeyJoinColumn item! /><#if item_has_next>, </#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>			

<#macro AttributeOverride item>
	<#if item??>
<@compress single_line=true>
	@AttributeOverride(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if></@compress>
		<#if item.column??>
<@compress single_line=true>
			<#if f>, </#if>
			<@Column item.column!/></@compress>
		</#if>
		)
	</#if>
</#macro>
						
<#macro AttributeOverrides attributeOverrides>
	<#if attributeOverrides??>
	<#if (attributeOverrides?size > 0)>
		<#if (attributeOverrides?size == 1)>
			<@AttributeOverride attributeOverrides[0]! />
		<#else>
@AttributeOverrides({			
<#list attributeOverrides as item>
<@compress single_line=true>
			<@AttributeOverride item! /><#if item_has_next>, </#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>				


<#macro Table table>
<#if table??>	
<@compress single_line=true>
	@Table(
		<#local f = false>
		<#if table.name??>
			${p(table.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if table.catalog??>
			${p(table.catalog!, "catalog", f)}
			<#local f = true>
		</#if>
		<#if table.schema??>
			${p(table.schema!, "schema", f)}
			<#local f = true>
		</#if></@compress>
		<#if table.uniqueConstraints??>
<#if f>,</#if>
			<@UniqueConstraints table.uniqueConstraints! />
			<#local f = true>
		</#if>
		)
</#if>		
</#macro>		 		 




<#macro SecondaryTable item>
	<#if item??>
<@compress single_line=true>
	@SecondaryTable(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if item.catalog??>
			${p(item.catalog!, "catalog", f)}
			<#local f = true>
		</#if>
		<#if item.schema??>
			${p(item.schema!, "schema", f)}
			<#local f = true>
		</#if></@compress>
		<#if item.pkJoinColumns??>
<#if f>,</#if>
			<@pkJoinColumns item.pkJoinColumns! />
			<#local f = true>
		</#if>
		<#if item.uniqueConstraints??>
<#if f>,</#if>
			<@UniqueConstraints item.uniqueConstraints! />
			<#local f = true>
		</#if>
		)
	</#if>
</#macro>
						
<#macro SecondaryTables secondaryTables>
	<#if secondaryTables??>
	<#if (secondaryTables?size > 0)>
		<#if (secondaryTables?size == 1)>
<@compress single_line=true>
			<@SecondaryTable secondaryTables[0]! /></@compress>
		<#else>
@SecondaryTables({			
<#list secondaryTables as item>
<@compress single_line=true>
			<@SecondaryTable item! /><#if item_has_next>, </#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>		

<#macro IdClass idClass>
	<#if idClass??>
@IdClass(${idClass}.class)
	</#if>
</#macro>

<#macro TableGenerator tableGenerator>
	<#if tableGenerator??>
<@compress single_line=true>
@TableGenerator(
		<#local f = false>
		<#if tableGenerator.name??>
			${p(tableGenerator.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.table??>
			${p(tableGenerator.table!, "table", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.catalog??>
			${p(tableGenerator.catalog!, "catalog", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.schema??>
			${p(tableGenerator.schema!, "schema", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.pkColumnName??>
			${p(tableGenerator.pkColumnName!, "pkColumnName", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.valueColumnName??>
			${p(tableGenerator.valueColumnName!, "valueColumnName", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.pkColumValue??>
			${p(tableGenerator.pkColumValue!, "pkColumValue", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.initialValue??>
			${p(tableGenerator.initialValue!, "initialValue", f)}
			<#local f = true>
		</#if>
		<#if tableGenerator.allocationSize??>
			${p(tableGenerator.allocationSize!, "allocationSize", f)}
			<#local f = true>
		</#if></@compress>
		<#if tableGenerator.uniqueConstraints??>
			<#if f>, </#if>
			<@UniqueConstraints item.uniqueConstraints! />
			<#local f = true>
		</#if>
		)
	</#if>	
</#macro>	


<#macro SequenceGenerator sequenceGenerator>
	<#if sequenceGenerator??>
<@compress single_line=true>
@SequenceGenerator(
		<#local f = false>
		<#if sequenceGenerator.name??>
			${p(sequenceGenerator.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if sequenceGenerator.sequenceName??>
			${p(sequenceGenerator.sequenceName!, "sequenceName", f)}
			<#local f = true>
		</#if>
)</@compress>
	</#if>	
</#macro>	


<#macro Parameter item>
	<#if item??>
<@compress single_line=true>
	@Parameter(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if item.value??>
			${p(item.value!, "value", f)}
			<#local f = true>
		</#if>
		)</@compress>
	</#if>
</#macro>
	
						
<#macro Parameters seq>
	<#if seq??>
	<#if (seq?size > 0)>
		<#if (seq?size == 1)>
<@compress single_line=true>
parameters = 
			<@Parameter seq[0]! /></@compress>
		<#else>
parameters = ({			
<#list seq as item>
<@compress single_line=true>
			<@Parameter item! /><#if item_has_next>, </#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>			
						

<#macro HibernateGenerator hibernateGenerator>
	<#if hibernateGenerator??>
<@compress single_line=true>
@HibernateGenerator(
		<#local f = false>
		<#if hibernateGenerator.name??>
			${p(hibernateGenerator.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if hibernateGenerator.strategy??>
			${p(hibernateGenerator.strategy!, "strategy", f)}
			<#local f = true>
		</#if></@compress>
		<#if hibernateGenerator.parameters??>
			<#if f>, </#if>
			<@Parameters hibernateGenerator.parameters! />
			<#local f = true>
		</#if>
)
	</#if>	
</#macro>	



<#macro Class e>
	<#if e.className??>
		<#if e.extends??>
			<#if e.implements??>
public class ${e.className} extends ${e.extends} implements ${e.implements}, Serializable
			<#else>
public class ${e.className} extends ${e.extends} implements Serializable
			</#if>
		<#else>
			<#if e.implements??>
public class ${e.className} implements ${e.implements}, Serializable
			<#else>
public class ${e.className} implements Serializable
			</#if>
		</#if>
	</#if>
</#macro>			
				


<#macro GeneratedValue e>
	<#if e.generatedValue??>
<@compress single_line=true>
@GeneratedValue(
		<#local f = false>
		<#if e.generatedValue.strategy??>
			${pb(e.generatedValue.strategy!, "strategy", f)}
			<#local f = true>
		</#if>
		<#if e.generatedValue.generator??>
			${p(e.generatedValue.generator!, "generator", f)}
			<#local f = true>
		</#if>
		)</@compress>
	</#if>
</#macro>						



<#macro IdField item>
	<#if item??>
		<@Column item.column!/>
		private ${item.type!} ${item.name!};	
	</#if>		
</#macro>

<#macro Id item>
	<#if item??>
	@Id
<#if item.tableGenerator??>
	<@TableGenerator item.tableGenerator!/>
</#if>
<#if item.sequenceGenerator??>
	<@SequenceGenerator item.sequenceGenerator!/>
</#if>
<#if item.hibernateGenerator??>
	<@HibernateGenerator item.hibernateGenerator!/>		
</#if>
	<@IdField item!/>
	</#if>	
</#macro>
	

<#macro Ids e>
	<#if e.ids??>
		<#if (e.ids?size > 0)>
			<#if (e.ids?size == 1)>
				<@GeneratedValue e! />	
				<@Id e.ids[0]! />
			<#else>	
	<#list e.ids as item>
				<@Id item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		
				
				
				
<#macro EmbeddedId embeddedId>
	<#if embeddedId??>
		<#if embeddedId.type?? && embeddedId.name??>
		@EmbeddedId
		private	${embeddedId.type} ${embeddedId.name};
		</#if>
	</#if>
</#macro>						
	
<#macro Transient transient>
	<#if transient??>
		@Transient
	</#if>
</#macro>	


<#macro Basic item>
	<#if item??>
		@Basic(
		<#local f = false>
		<#if item.fetch??>
			${p(item.fetch!, "fetch", f)}
			<#local f = true>
		</#if>
		<#if item.optional??>
			${p(item.optional!, "optional", f)}
			<#local f = true>
		</#if>
		)
	</#if>
</#macro>						

<#macro Temporal temporal>
	<#if temportal??>
		@Temporal(${temportal})
	</#if>
</#macro>		

<#macro Enumerated enumerated>
	<#if enumerated??>
		@Enumerated(${enumerated})
	</#if>
</#macro>	
<#macro Lob lob>
	<#if lob??>
		@Lob
	</#if>
</#macro>	
<#macro Version version>
	<#if version??>
		@Version
	</#if>
</#macro>	

<#macro Field item>
	<#if item??>
<#if item.column??>
		<@Column item.column! />
</#if>
<#if item.transient??>
		<@Transient item.transient! />
</#if>
<#if item.basic??>
		<@Basic item.basic! />
</#if>
<#if item.temporal??>
		<@Temporal item.temporal! />
</#if>
<#if item.enumerated??>
		<@Enumerated item.enumerated! />	
</#if>
<#if item.lob??>
		<@Lob item.lob! />	
</#if>
<#if item.version??>
		<@Version item.version! />
</#if>
<#if item.type?? && item.name??>
		private ${item.type!} ${item.name!};	
</#if>	
	</#if>	
</#macro>		

<#macro Fields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@Field fields[0]! />
			<#else>	
	<#list fields as item>
				<@Field item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		



<#macro EmbeddedField item>
	<#if item??>
		@Embedded	
		<@AttributeOverrides item.attributeOverrides! />
		private ${item.type!} ${item.name!};		
	</#if>	
</#macro>		

<#macro EmbeddedFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@EmbeddedField fields[0]! />
			<#else>	
	<#list fields as item>
				<@EmbeddedField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		



<#macro JoinColumn item>
	<#if item??>
<@compress single_line=true>
	@JoinColumn(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if item.referencedColumnName??>
			${p(item.referencedColumnName!, "referencedColumnName", f)}
			<#local f = true>
		</#if>
		<#if item.unique??>
			${p(item.unique!, "unique", f)}
			<#local f = true>
		</#if>
		<#if item.nullable??>
			${p(item.nullable!, "nullable", f)}
			<#local f = true>
		</#if>
		<#if item.insertable??>
			${p(item.insertable!, "insertable", f)}
			<#local f = true>
		</#if>
		<#if item.updatable??>
			${p(item.updatable!, "updatable", f)}
			<#local f = true>
		</#if>
		<#if item.columnDefinition??>
			${p(item.columnDefinition!, "columnDefinition", f)}
			<#local f = true>
		</#if>
		<#if item.table??>
			${p(item.table!, "table", f)}
			<#local f = true>
		</#if>
	)</@compress>
	</#if>	
</#macro>
						
<#macro JoinColumns seq>
	<#if seq??>
	<#if (seq?size > 0)>
		<#if (seq?size == 1)>
<@compress single_line=true>
			<@JoinColumn seq[0]! /></@compress>
		<#else>
@JoinColumns({			
<#list seq as pk>
<@compress single_line=true>
			<@JoinColumn pk! /><#if pk_has_next>, </#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>			
		
						
<#macro JoinTableJoinColumns seq>
	<#if seq??>
	<#if (seq?size > 0)>
		<#if (seq?size == 1)>
<@compress single_line=true>
joinColumns = 
			<@JoinColumn seq[0]! /></@compress>
		<#else>
joinColumns = ({			
<#list seq as item>
<@compress single_line=true>
			<@JoinColumn item! /><#if item_has_next>,</#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>			

						
<#macro JoinTableInverseJoinColumns seq>
	<#if seq??>
	<#if (seq?size > 0)>
		<#if (seq?size == 1)>
<@compress single_line=true>
inverseJoinColumns = 
			<@JoinColumn seq[0]! /></@compress>
		<#else>
inverseJoinColumns = ({			
<#list seq as item>
<@compress single_line=true>
			<@JoinColumn item! /><#if item_has_next>,</#if></@compress>
</#list>
})
	</#if>
</#if>
</#if>
</#macro>		

<#macro JoinTable item>
	<#if item??>
<@compress single_line=true>
	@JoinTable(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if item.catalog??>
			${p(item.catalog!, "catalog", f)}
			<#local f = true>
		</#if>
		<#if item.schema??>
			${p(item.schema!, "schema", f)}
			<#local f = true>
		</#if>
		<#if item.nullable??>
			${p(item.nullable!, "nullable", f)}
			<#local f = true>
		</#if></@compress>
		<#if item.joinColumns??>
<#if f>,</#if>
			<@JoinTableJoinColumns item.joinColumns! />
		</#if>
		<#if item.inverseJoinColumns??>
<#if f>,</#if>
			<@JoinTableInverseJoinColumns item.inverseJoinColumns! />
		</#if>
		<#if item.uniqueConstraints??>
<#if f>,</#if>
			<@UniqueConstraints item.uniqueConstraints! />
		</#if>
		)
	</#if>	
</#macro>	


<#macro IndexColumn item>
	<#if item??>
<@compress single_line=true>
	@IndexColumn(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if item.base??>
			${p(item.base!, "base", f)}
			<#local f = true>
		</#if>
		)</@compress>
	</#if>	
</#macro>	

<#macro Key item>
	<#if item??>
<@compress single_line=true>
	@MapKey(
		<#local f = false>
		<#if item.name??>
			${p(item.name!, "name", f)}
			<#local f = true>
		</#if>
		<#if item.base??>
			${p(item.base!, "base", f)}
			<#local f = true>
		</#if>
		)</@compress>
	</#if>	
</#macro>	


<#macro CollectionField item>
	<#if item??>
		@CollectionOfElements
<#if item.joinTable??>
		<@JoinTable item.joinTable! />
</#if>
<#if item.attributeOverrides??>
		<@AttributeOverrides item.attributeOverrides! />
</#if>
<#if item.key??>
		<@Key item.key! />
</#if>
<#if item.indexColumn??>
		<@IndexColumn item.indexColumn! />	
</#if>
<#if item.column??>
		<@Column item.column! />
</#if>
<#if item.type?? && item.name??>
		private ${item.type?replace('\'', '<', 'f')?replace('\'', '>')} ${item.name!};		
	</#if>		
	</#if>	
</#macro>		

<#macro CollectionFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@CollectionField fields[0]! />
			<#else>	
	<#list fields as item>
				<@CollectionField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		


<#macro OneToOne item>
	<#if item??>
<@compress single_line=true>
		@OneToOne(
		<#local f = false>
		<#if item.targetEntity??>
			${p(item.targetEntity!, "targetEntity", f)}
			<#local f = true>
		</#if>
		<#if item.cascade??>
			${p(item.cascade!, "cascade", f)}
			<#local f = true>
		</#if>
		<#if item.fetch??>
			${p(item.fetch!, "fetch", f)}
			<#local f = true>
		</#if>
		<#if item.optional??>
			${p(item.optional!, "optional", f)}
			<#local f = true>
		</#if>
		<#if item.mappedBy??>
			${p(item.mappedBy!, "mappedBy", f)}
			<#local f = true>
		</#if>
		)</@compress>
<#if item.primaryKeyJoinColumn??>
		<@PrimaryKeyJoinColumn item.primaryKeyJoinColumn! />
		</#if>
<#if item.joinTable??>
		<@JoinTable item.joinTable! />
		</#if>
<#if item.joinColumns??>
		<@JoinColumns item.joinColumns! />
		</#if>
<#if item.entity?? && item.name??>
		private ${item.entity!} ${item.name!};		
		</#if>
	</#if>	
</#macro>		

<#macro OneToOnes fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@OneToOne fields[0]! />
			<#else>	
	<#list fields as item>
				<@OneToOne item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

<#macro OneToMany item>
	<#if item??>
		<#if item.one!false>
<@compress single_line=true>
			@OneToMany(
			<#local f = false>
			<#if item.targetEntity??>
				${p(item.targetEntity!, "targetEntity", f)}
				<#local f = true>
			</#if>
			<#if item.cascade??>
				${p(item.cascade!, "cascade", f)}
				<#local f = true>
			</#if>
			<#if item.fetch??>
				${p(item.fetch!, "fetch", f)}
				<#local f = true>
			</#if>
			<#if item.optional??>
				${p(item.optional!, "optional", f)}
				<#local f = true>
			</#if>
			<#if item.mappedBy??>
				${p(item.mappedBy!, "mappedBy", f)}
				<#local f = true>
			</#if>
			)</@compress>
	<#if item.joinTable??>
			<@JoinTable item.joinTable! />
			</#if>
	<#if item.joinColumns??>
			<@JoinColumns item.joinColumns! />
			</#if>
			<#if item.orderBy??>
				@OrderBy("${item.orderBy!}")
			</#if>
			<#if item.mapkey??>
				@MapKey(name="${item.mapkey!}")
			</#if>
		private ${item.collectionType?replace('\'', '<', 'f')?replace('\'', '>')} ${item.name!};	
		<#else>
<@compress single_line=true>
			@ManyToOne(
			<#local f = false>
			<#if item.targetEntity??>
				${p(item.targetEntity!, "targetEntity", f)}
				<#local f = true>
			</#if>
			<#if item.cascade??>
				${pb(item.cascade!, "cascade", f)}
				<#local f = true>
			</#if>
			<#if item.fetch??>
				${pb(item.fetch!, "fetch", f)}
				<#local f = true>
			</#if>
			<#if item.optional??>
				${p(item.optional!, "optional", f)}
				<#local f = true>
			</#if>
			<#if item.mappedBy??>
				${p(item.mappedBy!, "mappedBy", f)}
				<#local f = true>
			</#if>
			)</@compress>
	<#if item.joinTable??>
			<@JoinTable item.joinTable! />
			</#if>
	<#if item.joinColumns??>
			<@JoinColumns item.joinColumns! />
			</#if>
		private ${item.entity!} ${item.name!};	
		</#if>	
	</#if>	
</#macro>		

<#macro OneToManys fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@OneToMany fields[0]! />
			<#else>	
	<#list fields as item>
				<@OneToMany item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		






<#macro ManyToMany item>
	<#if item??>
<@compress single_line=true>
		@ManyToMany(
		<#local f = false>
		<#if item.targetEntity??>
			${p(item.targetEntity!, "targetEntity", f)}
			<#local f = true>
		</#if>
		<#if item.cascade??>
			${p(item.cascade!, "cascade", f)}
			<#local f = true>
		</#if>
		<#if item.fetch??>
			${p(item.fetch!, "fetch", f)}
			<#local f = true>
		</#if>
		<#if item.optional??>
			${p(item.optional!, "optional", f)}
			<#local f = true>
		</#if>
		<#if item.mappedBy??>
			${p(item.mappedBy!, "mappedBy", f)}
			<#local f = true>
		</#if>
		)</@compress>
<#if item.joinTable??>
		<@JoinTable item.joinTable! />
		</#if>
		private ${item.collectionType?replace('\'', '<', 'f')?replace('\'', '>')} ${item.name!};		
	</#if>	
</#macro>		

<#macro ManyToManys fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@ManyToMany fields[0]! />
			<#else>	
	<#list fields as item>
				<@ManyToMany item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		


<#macro getId item>
	<#if item??>
		public ${item.type!} get${item.name?cap_first}()
		{
				return ${item.name!};
		}		
	</#if>	
</#macro>
	

<#macro getIds e>
	<#if e.ids??>
		<#if (e.ids?size > 0)>
			<#if (e.ids?size == 1)>
				<@getId e.ids[0]! />
			<#else>	
	<#list e.ids as item>
				<@getId item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

<#macro setId item>
	<#if item??>
		public void set${item.name?cap_first}(${item.type!} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}		
	</#if>	
</#macro>
	

<#macro setIds e>
	<#if e.ids??>
		<#if (e.ids?size > 0)>
			<#if (e.ids?size == 1)>
				<@setId e.ids[0]! />
			<#else>	
	<#list e.ids as item>
				<@setId item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

				
<#macro getEmbeddedId embeddedId>
	<#if embeddedId??>
		<#if embeddedId.type?? && embeddedId.name??>
		public	${embeddedId.type} get${embeddedId.name?cap_first}()
		{
				return ${embeddedId.name!};
		}		
		</#if>
	</#if>
</#macro>		
				
<#macro setEmbeddedId embeddedId>
	<#if embeddedId??>
		<#if embeddedId.type?? && embeddedId.name??>
		public void set${embeddedId.name?cap_first}(${embeddedId.type!} ${embeddedId.name!})
		{
				this.${embeddedId.name!} = ${embeddedId.name!};
		}		
		</#if>
	</#if>
</#macro>		


<#macro getField item>
	<#if item??>
		public ${item.type!} get${item.name?cap_first}()
		{
				return ${item.name!};
		}		
	</#if>	
</#macro>		

<#macro getFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@getField fields[0]! />
			<#else>	
	<#list fields as item>
				<@getField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>	
<#macro setField item>
	<#if item??>
		public void set${item.name?cap_first}(${item.type!} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}		
	</#if>	
</#macro>		

<#macro setFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@setField fields[0]! />
			<#else>	
	<#list fields as item>
				<@setField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>	


<#macro getEmbeddedField item>
	<#if item??>
		public ${item.type!} get${item.name?cap_first}()
		{
				return ${item.name!};
		}			
	</#if>	
</#macro>		

<#macro getEmbeddedFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@getEmbeddedField fields[0]! />
			<#else>	
	<#list fields as item>
				<@getEmbeddedField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

<#macro setEmbeddedField item>
	<#if item??>
		public void set${item.name?cap_first}(${item.type!} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}		
	</#if>	
</#macro>		

<#macro setEmbeddedFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@setEmbeddedField fields[0]! />
			<#else>	
	<#list fields as item>
				<@setEmbeddedField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		


<#macro getCollectionField item>
	<#if item??>
		public ${item.type?replace('\'', '<', 'f')?replace('\'', '>')} get${item.name?cap_first}()
		{
				return ${item.name!};
		}			
	</#if>	
</#macro>		

<#macro getCollectionFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@getCollectionField fields[0]! />
			<#else>	
	<#list fields as item>
				<@getCollectionField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

<#macro setCollectionField item>
	<#if item??>
		public void set${item.name?cap_first}(${item.type?replace('\'', '<', 'f')?replace('\'', '>')} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}		
	</#if>	
</#macro>		

<#macro setCollectionFields fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@setCollectionField fields[0]! />
			<#else>	
	<#list fields as item>
				<@setCollectionField item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		



<#macro getOneToOne item>
	<#if item??>
		public ${item.entity!} get${item.name?cap_first}()
		{
				return ${item.name!};
		}			
	</#if>	
</#macro>		

<#macro getOneToOnes fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@getOneToOne fields[0]! />
			<#else>	
	<#list fields as item>
				<@getOneToOne item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

<#macro setOneToOne item>
	<#if item??>
		public void set${item.name?cap_first}(${item.entity!} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}	
	</#if>	
</#macro>		

<#macro setOneToOnes fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@setOneToOne fields[0]! />
			<#else>	
	<#list fields as item>
				<@setOneToOne item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		



<#macro getOneToMany item>
	<#if item??>
		<#if item.one!false>
		public ${item.collectionType?replace('\'', '<', 'f')?replace('\'', '>')} get${item.name?cap_first}()
		{
				return ${item.name!};
		}		
		<#else>
		public ${item.entity!} get${item.name?cap_first}()
		{
				return ${item.name!};
		}		
		</#if>
	</#if>	
</#macro>		

<#macro getOneToManys fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@getOneToMany fields[0]! />
			<#else>	
	<#list fields as item>
				<@getOneToMany item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

<#macro setOneToMany item>
	<#if item??>
		<#if item.one!false>
		public void set${item.name?cap_first}(${item.collectionType?replace('\'', '<', 'f')?replace('\'', '>')} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}	
		<#else>
		public void set${item.name?cap_first}(${item.entity!} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}	
		</#if>
	</#if>	
</#macro>		

<#macro setOneToManys fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@setOneToMany fields[0]! />
			<#else>	
	<#list fields as item>
				<@setOneToMany item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		



<#macro getManyToMany item>
	<#if item??>
		public ${item.collectionType?replace('\'', '<', 'f')?replace('\'', '>')} get${item.name?cap_first}()
		{
				return ${item.name!};
		}			
	</#if>	
</#macro>		

<#macro getManyToManys fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@getManyToMany fields[0]! />
			<#else>	
	<#list fields as item>
				<@getManyToMany item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>		

<#macro setManyToMany item>
	<#if item??>
		public void set${item.name?cap_first}(${item.collectionType?replace('\'', '<', 'f')?replace('\'', '>')} ${item.name!})
		{
				this.${item.name!} = ${item.name!};
		}			
	</#if>	
</#macro>		

<#macro setManyToManys fields>
	<#if fields??>
		<#if (fields?size > 0)>
			<#if (fields?size == 1)>
				<@setManyToMany fields[0]! />
			<#else>	
	<#list fields as item>
				<@setManyToMany item! />
	</#list>
			</#if>
		</#if>
	</#if>
</#macro>